package com.example.demo.controller;

import com.example.demo.entity.Customer;
import com.example.demo.entity.ResponseResult;
import com.example.demo.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;

@RestController
@RequestMapping("/customer")
@Api(tags = "顾客接口")
public class CustomerController {

    @Resource
    private CustomerService customerService;


    @GetMapping
    @ApiOperation(value = "查询全部顾客信息")
    public ResponseResult getList(){
        return customerService.getList();
    }

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult getCustomerById(@PathParam(value = "id") Integer id){
        return customerService.getCustomerById(id);
    }

    @GetMapping("/getByName/{name}")
    @ApiOperation(value = "根据顾客名称查询")
    public ResponseResult getCustomerByName(@PathParam(value = "name") String name){
        return customerService.getCustomerByName(name);
    }

    @PostMapping
    @ApiOperation(value = "新增顾客信息")
    public ResponseResult saveCustomer(@RequestBody Customer customer){
        return customerService.saveCustomer(customer);
    }

    @PutMapping
    @ApiOperation(value = "更新顾客信息")
    public ResponseResult updateCustomer(@RequestBody Customer customer){
        return customerService.updateCustomer(customer);
    }

    @DeleteMapping("/deleteById")
    @ApiOperation(value = "根据id删除顾客")
    public ResponseResult deleteById(@RequestParam String id){
        return customerService.deleteById(id);
    }

    @DeleteMapping("/deleteByName")
    @ApiOperation(value = "根据名称删除顾客")
    public ResponseResult deleteByName(@RequestParam String name){
        return customerService.deleteByName(name);
    }
}
